const request = options => {
  return new Promise((resolve, reject) => {
    const {
      data,
      method,
      token
    } = options
    if (data && method !== 'get') {
      options.data = JSON.stringify(data)
    }
    wx.request({
      header: {
        'Content-Type': 'application/json',
        'Authorization': token
      },
      ...options,
      success: function (res) {
        if (res.statusCode === 200) {
          resolve(res.data)
        } else {
          reject(res.data)
        }
      },
      fail: function (res) {
        reject(res.data)
      }
    })
  })
}
export default request